package com.jf3q.teacher.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.common.dto.ResultDto;
import com.jf3q.teacher.pojo.Teacher;
import com.jf3q.teacher.service.TeacherService;
import com.jf3q.teacher.vo.SearchTeacherVo;
import com.jf3q.teacher.vo.TeacherVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author:xiaojie
 * @create: 2023-06-27 13:51
 * @Description:
 */

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    TeacherService eduTeacherService;

    @PostMapping("/save")
    @ApiOperation(value = "讲师保存接口")
    public ResultDto save(@RequestBody @Validated TeacherVo teacherVo){

        Teacher eduTeacher = new Teacher();
        BeanUtils.copyProperties(teacherVo,eduTeacher);
        eduTeacherService.save(eduTeacher);

        return ResultDto.success("添加讲师成功",null);

    }
    @PostMapping("page/{pageNum}")
    @ApiOperation(value = "讲师分页查询接口")
    public ResultDto get( @PathVariable Integer pageNum,
                          @RequestBody(required = false) SearchTeacherVo searchTeacherVo){

        Page<Teacher> page=eduTeacherService.getPage(pageNum,searchTeacherVo);
        return ResultDto.success("查询所有讲师",page);
    }

    @ApiOperation(value = "删除讲师")
    @DeleteMapping("/{id}")
    public ResultDto del(@PathVariable String id){

        Boolean flag=eduTeacherService.del(id);
        if (flag) {
            return ResultDto.success("删除成功",null);
        }
        return ResultDto.error("删除失败");

    }
}
